package com.lr.wfxmanager.merchant.controller;

import com.lr.wfxmanager.globa.bean.JsonResultVo;
import com.lr.wfxmanager.merchant.bean.WxbCustomer;
import com.lr.wfxmanager.merchant.service.IMerchantService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("merchant")
public class MerchantController {
    @Resource
    private IMerchantService iMerchantService;
    /*查询商户列表*/
    @RequestMapping("merchant-list")
    public String list(Model model){
        List<WxbCustomer> merchantList = iMerchantService.queryMerchantList();
        model.addAttribute("list",merchantList);
        return "merchant-list";
    }
    @ResponseBody
    @RequestMapping("add")
    public JsonResultVo addMerchant(WxbCustomer wxbCustomer){
            JsonResultVo resultVo = new JsonResultVo();
        try {
            iMerchantService.addMerchant(wxbCustomer);
            resultVo.setMark(1);//添加成功
        } catch (Exception e) {
            resultVo.setMark(0);
            e.printStackTrace();
        }

        return resultVo;
    }
}
